package com.competitions.easydubbing.controller;

import com.competitions.easydubbing.entity.Result;
import com.competitions.easydubbing.service.CommunityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author Mapler
 * @since 2021-5-20
 */
@RestController
@RequestMapping(value = "/community")
public class CommunityController {
    private final CommunityService communityService;

    @Autowired
    public CommunityController(CommunityService communityService) {
        this.communityService = communityService;
    }

    @RequestMapping(value = "/publishVideo",method = RequestMethod.POST)
    public ResponseEntity<Result> publishVideo(
            @RequestParam("uid")int uid,
            @RequestParam("title")String title,
            @RequestParam("desc")String desc,
            @RequestParam("channel")String channel,
            @RequestBody MultipartFile cover,
            @RequestBody MultipartFile video){
        return communityService.publishVideo(uid, title, desc, channel, cover, video);
    }

    @RequestMapping(value = "/publishDirectly",method = RequestMethod.POST)
    public ResponseEntity<Result> publishDirectly(
            @RequestParam("uid")int uid,
            @RequestParam("title")String title,
            @RequestParam("desc")String desc,
            @RequestParam("channel")String channel,
            @RequestParam("videoPath")String videoPath,
            @RequestBody MultipartFile cover){
        return communityService.publishDirectly(uid, title, desc, channel, videoPath,cover);
    }

    @RequestMapping(value = "/deleteVideo",method = RequestMethod.GET)
    public ResponseEntity<Result> deleteVideo(@RequestParam("vid")int vid){
        return communityService.deleteVideo(vid);
    }

    @RequestMapping(value = "/changeNum",method = RequestMethod.GET)
    public ResponseEntity<Result> changeNum(
            @RequestParam("vid")int vid,
            @RequestParam("field")String field,
            @RequestParam("type")int type,
            @RequestParam("uid")int uid
            ){
        return communityService.changeNum(vid, field, type,uid);
    }

    @RequestMapping(value = "/sendComment",method = RequestMethod.GET)
    public ResponseEntity<Result> changeNum(
            @RequestParam("vid")int vid,
            @RequestParam("comment")String comment,
            @RequestParam("uid")int uid
    ){
        return communityService.sendComment(vid,comment,uid);
    }

    @RequestMapping(value = "/findIndexList",method = RequestMethod.GET)
    public ResponseEntity<Result> findIndexList(@RequestParam("uid")int uid){
        return communityService.findIndexList(uid);
    }

    @RequestMapping(value = "/commentList",method = RequestMethod.GET)
    public ResponseEntity<Result> commentList(@RequestParam("vid")int vid){
        return communityService.commentList(vid);
    }

    @RequestMapping(value = "/findHistoryList",method = RequestMethod.GET)
    public ResponseEntity<Result> findHistoryList(@RequestParam("uid")int uid){
        return communityService.findHistoryList(uid);
    }
}
